<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

/**
 * 欢迎模块
 */


/**
 * 前台注册登录
 */

//注册页面
Route::get('/register', '\App\Http\Controllers\RegisterController@index');
//注册行为
Route::post('/register', '\App\Http\Controllers\RegisterController@register');
//登录页面
Route::get('/login', '\App\Http\Controllers\LoginController@index');
//登录行为
Route::post('/login', '\App\Http\Controllers\LoginController@login');

/**
 * 前台路由组
 */

Route::group(['middleware' => 'auth:web'], function () {

    Route::get('/', '\App\Http\Controllers\PostController@index');

    /**
     * 文章模块
     */

    //文章列表
    Route::get('/posts', '\App\Http\Controllers\PostController@index');

    //文章搜索
    Route::get('/posts/search', '\App\Http\Controllers\PostController@search');

    //创建文章
    Route::get('/posts/create', '\App\Http\Controllers\PostController@create');

    //文章详情
    Route::get('/posts/{post}', '\App\Http\Controllers\PostController@show');

    //文章评论行为
    Route::post('/posts/{post}/comment', '\App\Http\Controllers\PostController@comment');

    //文章点赞行为
    Route::get('/posts/{post}/zan', '\App\Http\Controllers\PostController@zan');

    //文章取消赞行为
    Route::get('/posts/{post}/unzan', '\App\Http\Controllers\PostController@unzan');

    //创建文章行为
    Route::post('/posts', '\App\Http\Controllers\PostController@store');

    //编辑文章
    Route::get('/posts/{post}/edit', '\App\Http\Controllers\PostController@edit');

    //编辑文章行为
    Route::put('/posts/{post}', '\App\Http\Controllers\PostController@update');

    //文章图片上传
    Route::post('/posts/image/upload', '\App\Http\Controllers\PostController@imageUpload');

    //删除文章
    Route::get('/posts/{post}/delete', '\App\Http\Controllers\PostController@delete');

    /**
     * 用户模块
     */
    //个人中心
    Route::get('/user/{user}', '\App\Http\Controllers\UserController@index');

    //个人中心设置页面
    Route::get('/user/{user}/setting', '\App\Http\Controllers\UserController@setting');

    //个人中心设置行为
    Route::post('/user/{user}/setting', '\App\Http\Controller\UserController@settingStore');

    //个人中心关注某人
    Route::post('/user/{user}/fan', '\App\Http\Controller\UserController@fan');

    //个人中心取消关注某人
    Route::post('/user/{user}/unfan', '\App\Http\Controller\UserController@unFan');

    /***
     * 专题
     */

    //专题页
    Route::get('/topic/{topic}', '\App\Http\Controllers\TopicController@index');

    //专题投稿
    Route::post('/topic/{topic}/submit', '\App\Http\Controllers\TopicController@submit');

    //登出行为
    Route::get('/logout', '\App\Http\Controllers\LoginController@logout');

    /*
     * 专题模块
     */
    Route::get('/notices', '\App\Http\Controllers\NoticeController@index');

});


/***
 * 后台路由组
 */

Route::group(['prefix' => 'admin'], function () {

    //登录页
    Route::get('/login', '\App\Http\Controllers\Admin\LoginController@index');

    //登录行为
    Route::post('/login', '\App\Http\Controllers\Admin\LoginController@login');

    //登出行为
    Route::get('/logout', '\App\Http\Controllers\Admin\LoginController@logout');

    Route::group(['middleware' => 'auth:admin'], function () {

        //后台首页
        Route::get('/home', '\App\Http\Controllers\Admin\HomeController@index');

        //系统管理
        Route::group(['middleware' => 'can:system'], function () {

            //管理人员列表
            Route::get('/users', '\App\Http\Controllers\Admin\UserController@index');
            //管理人员增加
            Route::get('/users/create', '\App\Http\Controllers\Admin\UserController@create');
            //管理人员增加行为
            Route::post('/users/store', '\App\Http\Controllers\Admin\UserController@store');
            //管理人员角色展示
            Route::get('/users/{user}/role', '\App\Http\Controllers\Admin\UserController@role');
            //管理人员角色关联
            Route::post('/users/{user}/role', '\App\Http\Controllers\Admin\UserController@storeRole');

            // 角色展示页
            Route::get('/roles', '\App\Http\Controllers\Admin\RoleController@index');
            //角色创建页
            Route::get('/roles/create', '\App\Http\Controllers\Admin\RoleController@create');
            //角色创建行为
            Route::post('/roles/store', '\App\Http\Controllers\Admin\RoleController@store');
            //角色权限关联页
            Route::get('/roles/{role}/permission', '\App\Http\Controllers\Admin\RoleController@permission');
            //角色权限关联行为
            Route::post('/roles/{role}/permission', '\App\Http\Controllers\Admin\RoleController@storePermission');

            //权限展示页
            Route::get('/permissions', '\App\Http\Controllers\Admin\PermissionController@index');
            //增加权限页
            Route::get('/permissions/create', '\App\Http\Controllers\Admin\PermissionController@create');
            //权限增加行为
            Route::post('/permissions/store', '\App\Http\Controllers\Admin\PermissionController@store');

        });

        //文章管理
        Route::group(['middleware' => 'can:post'], function () {

            //文章审核模块
            Route::get('/posts', '\App\Http\Controllers\Admin\PostController@index');
            //文章审核行为
            Route::post('/posts/{post}/status', '\App\Http\Controllers\Admin\PostController@status');

        });

        //专题管理
        Route::group(['middleware' => 'can:topic'], function () {
            Route::resource('topics', '\App\Http\Controllers\Admin\TopicController', ['only' => [
                'index', 'create', 'store', 'destroy'
            ]]);
        });

        // 通知模块
        Route::group(['middleware' => 'can:notice'], function () {
            Route::resource('notices', '\App\Http\Controllers\Admin\NoticeController', [
                'only' => ['index', 'create', 'store'],
            ]);
        });

    });

});
